/*
 * @Description:
 * @Author: 胡涛
 * @Date: 2023-10-12 22:13:33
 * @LastEditors: 胡涛
 * @LastEditTime: 2024-01-04 00:25:34
 */
import api from "@/api";
import { ListResultDto, PagedListResultDto } from "../types";
import {
  GetOrganizationInputDto,
  OrganizationDto,
  OrganizationTreeDto,
  AddOrganizationUsersInputDto,
} from "./types";
import { SystemUserDto } from "../system/types";

export default {
  /**
   * 获取单条记录
   * @param id
   * @param data
   * @returns
   */
  get(id: string): Promise<OrganizationDto> {
    return api.get("/api/Platform/Organize/organization/" + id);
  },
  /**
   * 获取列表
   * @param id
   * @param data
   * @returns
   */
  getList(
    data: Partial<GetOrganizationInputDto>
  ): Promise<PagedListResultDto<OrganizationDto>> {
    return api.get("/api/Platform/Organize/organization", data);
  },
  /**
   * 获取列表（不分页）
   * @param id
   * @param data
   * @returns
   */
  getAllList(
    data: Partial<GetOrganizationInputDto>
  ): Promise<Array<OrganizationDto>> {
    return api.get("/api/Platform/Organize/organization/all", data);
  },
  /**
   * 获取下拉树列表
   * @param name
   * @returns
   */
  getTreeList(
    data: Partial<GetOrganizationInputDto>
  ): Promise<Array<OrganizationTreeDto>> {
    return api.get(`/api/Platform/Organize/organization/trees`, data);
  },
  /**
   * 添加
   * @param id
   * @param data
   * @returns
   */
  create(data: Partial<OrganizationDto>): Promise<OrganizationDto> {
    return api.post("/api/Platform/Organize/organization", data);
  },
  /**
   * 修改
   * @param id
   * @param data
   * @returns
   */
  update(id: string, data: Partial<OrganizationDto>): Promise<OrganizationDto> {
    return api.put("/api/Platform/Organize/organization/" + id, data);
  },
  /**
   * 删除
   * @param id
   * @returns
   */
  delete(id: string): Promise<OrganizationDto> {
    return api.delete("/api/Platform/Organize/organization/" + id);
  },

  /**
   * 添加用户到机构
   * @param data
   * @returns
   */
  addUsers(data: AddOrganizationUsersInputDto): Promise<any> {
    return api.post("/api/Platform/Organize/organization/addUsers", data);
  },
  /**
   * 获取机构用户列表
   * @param id
   * @returns
   */
  getUsers(id: string): Promise<Array<SystemUserDto>> {
    return api.get("/api/Platform/Organize/organization/users/" + id);
  },

  /**
   *获取机构用户列表 （根据机构代码)
   * @param code
   * @returns
   */
  getUsersForCode(code: string): Promise<Array<SystemUserDto>> {
    return api.get("/api/Platform/Organize/organization/usersForCode/" + code);
  },
};
